import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import {
  GetHotJobRes,
  JobPageQuery,
  GetJobInfoPageRes,
  GetJobInfoByIdRes,
  BasePageQuery,
} from './type'
import qs from 'qs'

enum JOB_API {
  GET_HOST_JOB = '/job/hot',
  GET_JOB_PAGE_BY_SEEKER = '/job/more',
  GET_JOB_INFO_BY_ID = '/job/info/{id}',
  GET_JOB_INFO_BY_COMPANYID = '/job/company/{id}',
}

/**
 * 求职者获取热门职位
 * @returns
 */
export const reqGetHotJob = () =>
  request.get<any, AxiosResponse<GetHotJobRes>>(JOB_API.GET_HOST_JOB)

/**
 * 求职者获取职位分页
 * @param {string} jobPageQuery hr分页请求对象
 * @returns
 */
export const reqGetJobPageBySeeker = (data: JobPageQuery) =>
  request.get<any, AxiosResponse<GetJobInfoPageRes>>(
    JOB_API.GET_JOB_PAGE_BY_SEEKER + '?' + qs.stringify(data),
  )

/**
 * 求职者根据Id获取job
 * @param {string} id
 * @returns
 */
export const reqGetJobInfoById = (id: number) =>
  request.get<any, AxiosResponse<GetJobInfoByIdRes>>(
    JOB_API.GET_JOB_INFO_BY_ID.replace('{id}', id.toString()),
  )

/**
 * 根据公司Id获取job分页
 * @param {string} id
 * @param {string} basePageQuery
 * @returns
 */
export const reqGetJobInfoPageByCompanyId = (id: number, data: BasePageQuery) =>
  request.get<any, AxiosResponse<GetJobInfoPageRes>>(
    JOB_API.GET_JOB_INFO_BY_COMPANYID.replace('{id}', id.toString()) +
      '?' +
      qs.stringify(data),
  )
